package com.quanxiaoha.framework.common.validator;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

/**
 * @author: Jovan
 * @date: 2024/11/24
 * @description:
 */
public class PhoneNumberValidator implements ConstraintValidator<PhoneNumber, String> {
    @Override
    public void initialize(PhoneNumber constraintAnnotation) {
        // 初始化操作
    }

    @Override
    public boolean isValid(String phoneNumber, ConstraintValidatorContext context) {
        // 检查手机号码是否非空且符合中国大陆手机号码的正则表达式
        return phoneNumber != null && phoneNumber.matches("^1[3456789]\\d{9}$");
    }
}
